home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 12 / BBS in a box XII-1.iso / Files / Game / F-G / Glypha II 1.1.sit / Glypha II 1.1 ƒ / Glypha II 1.1 Source Code ƒ / Code ƒ / D-GameUtils.p < prev    next >
Encoding:
Text File  |  1992-07-03  |  29.3 KB  |  979 lines  |  [TEXT/PJMM]

  1. unit GameUtils;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Sound, Palettes, Globals, Dialogs;
  7.  
  8.     procedure CenterZeroRect (var theRect: Rect);
  9.     procedure NewLightning;
  10.     procedure StrikeLightning (whichLevel: Integer);
  11.     procedure DoTheSound (whichOne: Str255; priority: Integer);
  12.     function DoRandom (range: Integer): Integer;
  13.     procedure ChangeRect;
  14.     procedure DrawPlayer (newRect, oldRect: Rect);
  15.     procedure DrawBeasts;
  16.     procedure DrawHand;
  17.     procedure RedoTheBackground;
  18.     procedure ShowScore;
  19.     procedure ShowMortals;
  20.     procedure ShowLevel;
  21.     procedure CheckExtraMortal;
  22.     procedure ReDrawHiScores;
  23.     procedure ReadInScores;
  24.     procedure WriteOutScores;
  25.     procedure FinalScore;
  26.     procedure DoHelpScreen;
  27.     procedure FlushTheScores;
  28.  
  29. {=================================}
  30.  
  31. implementation
  32.  
  33. {=================================}
  34.  
  35.     procedure CenterZeroRect;
  36.     begin
  37.         OffsetRect(theRect, -theRect.left, -theRect.top);
  38.         OffsetRect(theRect, (theRect.left - theRect.right) div 2, (theRect.top - theRect.bottom) div 2);
  39.     end;
  40. {=================================}
  41.  
  42.     procedure NewLightning;
  43.  
  44.         const
  45.             obeliskHeight = 250;
  46.             obel1left = 172;
  47.             obel2left = 468;
  48.             pylonToCenter = 148;
  49.  
  50.             upperHeight = 180;
  51.             lowerHeight = 425;
  52.  
  53.             upperDelta = upperHeight - obeliskHeight;
  54.             lowerDelta = lowerHeight - obeliskHeight;
  55.  
  56.             upperEyeDelta = upperEyeHeight - obeliskHeight;
  57.             lowerEyeDelta = lowerEyeHeight - obeliskHeight;
  58.  
  59.         var
  60.             index, index2, travel, hori, vert: Integer;
  61.  
  62.     begin
  63.  
  64.         with lightning do
  65.             begin
  66.                 levelStriking := upperLevel;
  67.                 leftMode := DoRandom(4);
  68.                 rightMode := DoRandom(4);
  69.                 for index := 0 to 3 do
  70.                     begin
  71.                         SetPt(leftBolts[upperLevel, index, 0], obel1left, obeliskHeight);
  72.                         SetPt(rightBolts[upperLevel, index, 0], obel2left, obeliskHeight);
  73.                         SetPt(leftBolts[lowerLevel, index, 0], obel1left, obeliskHeight);
  74.                         SetPt(rightBolts[lowerLevel, index, 0], obel2left, obeliskHeight);
  75.                         SetPt(leftBolts[upperEye, index, 0], obel1left, obeliskHeight);
  76.                         SetPt(rightBolts[upperEye, index, 0], obel2left, obeliskHeight);
  77.                         SetPt(leftBolts[lowerEye, index, 0], obel1left, obeliskHeight);
  78.                         SetPt(rightBolts[lowerEye, index, 0], obel2left, obeliskHeight);
  79.                     end;
  80.                 for index := 0 to 3 do
  81.                     for index2 := 1 to 10 do
  82.                         begin
  83.                             travel := (6 - ABS(index2 - 6)) * 5;
  84.  
  85.                             hori := obel1left + (index2 * (pylonToCenter div 12));
  86.                             vert := obeliskHeight + (index2 * (upperDelta div 12));
  87.                             vert := vert + DoRandom(travel * 2) - travel;
  88.                             SetPt(leftBolts[upperLevel, index, index2], hori, vert);
  89.  
  90.                             hori := obel2left - (index2 * (pylonToCenter div 12));
  91.                             vert := obeliskHeight + (index2 * (upperDelta div 12));
  92.                             vert := vert + DoRandom(travel * 2) - travel;
  93.                             SetPt(rightBolts[upperLevel, index, index2], hori, vert);
  94.  
  95.                             hori := obel1left + (index2 * (pylonToCenter div 12));
  96.                             vert := obeliskHeight + (index2 * (lowerDelta div 12));
  97.                             vert := vert + DoRandom(travel * 2) - travel;
  98.                             SetPt(leftBolts[lowerLevel, index, index2], hori, vert);
  99.  
  100.                             hori := obel2left - (index2 * (pylonToCenter div 12));
  101.                             vert := obeliskHeight + (index2 * (lowerDelta div 12));
  102.                             vert := vert + DoRandom(travel * 2) - travel;
  103.                             SetPt(rightBolts[lowerLevel, index, index2], hori, vert);
  104.  
  105.                             hori := obel1left + (index2 * (pylonToCenter div 12));
  106.                             vert := obeliskHeight + (index2 * (upperEyeDelta div 12));
  107.                             vert := vert + DoRandom(travel * 2) - travel;
  108.                             SetPt(leftBolts[upperEye, index, index2], hori, vert);
  109.  
  110.                             hori := obel2left - (index2 * (pylonToCenter div 12));
  111.                             vert := obeliskHeight + (index2 * (upperEyeDelta div 12));
  112.                             vert := vert + DoRandom(travel * 2) - travel;
  113.                             SetPt(rightBolts[upperEye, index, index2], hori, vert);
  114.  
  115.                             hori := obel1left + (index2 * (pylonToCenter div 12));
  116.                             vert := obeliskHeight + (index2 * (lowerEyeDelta div 12));
  117.                             vert := vert + DoRandom(travel * 2) - travel;
  118.                             SetPt(leftBolts[lowerEye, index, index2], hori, vert);
  119.  
  120.                             hori := obel2left - (index2 * (pylonToCenter div 12));
  121.                             vert := obeliskHeight + (index2 * (lowerEyeDelta div 12));
  122.                             vert := vert + DoRandom(travel * 2) - travel;
  123.                             SetPt(rightBolts[lowerEye, index, index2], hori, vert);
  124.                         end;
  125.                 for index := 0 to 3 do
  126.                     begin
  127.                         SetPt(leftBolts[upperLevel, index, 11], 320, upperHeight);
  128.                         SetPt(rightBolts[upperLevel, index, 11], 318, upperHeight);
  129.                         SetPt(leftBolts[lowerLevel, index, 11], 320, lowerHeight);
  130.                         SetPt(rightBolts[lowerLevel, index, 11], 318, lowerHeight);
  131.                         SetPt(leftBolts[upperEye, index, 11], 320, upperEyeHeight);
  132.                         SetPt(rightBolts[upperEye, index, 11], 318, upperEyeHeight);
  133.                         SetPt(leftBolts[lowerEye, index, 11], 320, lowerEyeHeight);
  134.                         SetPt(rightBolts[lowerEye, index, 11], 318, lowerEyeHeight);
  135.                     end;
  136.             end;
  137.     end;
  138.  
  139. {=================================}
  140.  
  141.     procedure StrikeLightning;
  142.         var
  143.             index: Integer;
  144.             isPoint, wasPoint: Point;
  145.             savedPort: GrafPtr;
  146.     begin
  147.         GetPort(savedPort);
  148.         SetPort(GrafPtr(mainWndo));
  149.  
  150.         InvertRgn(obeliskRgn1);
  151.         InvertRgn(obeliskRgn2);
  152.         PenNormal;
  153.         PenSize(2, 2);
  154.         PenMode(patXOr);
  155.         with lightning do
  156.             begin
  157.                 leftMode := DoRandom(4);
  158.                 rightMode := DoRandom(4);
  159.                 for index := 1 to 11 do
  160.                     begin
  161.                         isPoint := leftBolts[whichLevel, leftMode, index];
  162.                         wasPoint := leftBolts[whichLevel, leftMode, index - 1];
  163.                         MoveTo(wasPoint.h, wasPoint.v);
  164.                         LineTo(isPoint.h - 2, isPoint.v);
  165.                         isPoint := rightBolts[whichLevel, leftMode, index];
  166.                         wasPoint := rightBolts[whichLevel, leftMode, index - 1];
  167.                         MoveTo(wasPoint.h, wasPoint.v);
  168.                         LineTo(isPoint.h + 2, isPoint.v);
  169.                     end;
  170.                 for index := 1 to 11 do
  171.                     begin
  172.                         isPoint := leftBolts[whichLevel, leftMode, index];
  173.                         wasPoint := leftBolts[whichLevel, leftMode, index - 1];
  174.                         MoveTo(wasPoint.h, wasPoint.v);
  175.                         LineTo(isPoint.h - 2, isPoint.v);
  176.                         isPoint := rightBolts[whichLevel, leftMode, index];
  177.                         wasPoint := rightBolts[whichLevel, leftMode, index - 1];
  178.                         MoveTo(wasPoint.h, wasPoint.v);
  179.                         LineTo(isPoint.h + 2, isPoint.v);
  180.                     end;
  181.             end;
  182.         InvertRgn(obeliskRgn1);
  183.         InvertRgn(obeliskRgn2);
  184.         SetPort(GrafPtr(savedPort));
  185.     end;
  186.  
  187. {=================================}
  188.  
  189.     function GetA5: LONGINT;
  190.     inline
  191.         $2E8D; {MOVE.L A5,(A7)}
  192.  
  193. {=================================}
  194.  
  195.     function LoadA5 (newA5: LONGINT): LONGINT;
  196.     inline
  197.         $2F4D, $0004, $2A5F;
  198.  
  199. {=================================}
  200.  
  201.     procedure ChanCallBack (chan: SndChannelPtr; cmd: SndCommand);
  202.         var
  203.             oldA5: LongInt;
  204.     begin
  205.         if cmd.param1 <> 12345 then
  206.             Exit(ChanCallBack);             { Skip err callBackCmd w/ System 6.0.4 }
  207.         oldA5 := LoadA5(cmd.param2);        { get the application's A5 and set it }
  208.         soundPriority := noSound;
  209.         oldA5 := LoadA5(oldA5);            { restore old A5 }
  210.     end;
  211.  
  212. {=================================}
  213.  
  214.     procedure DoTheSound;
  215.         var
  216.             aCommand: SndCommand;
  217.             theSnd: Handle;
  218.             err: OSErr;
  219.     begin
  220.         if (not soundOn) then
  221.             Exit(DoTheSound);
  222.  
  223.         if (priority < soundPriority) then
  224.             Exit(DoTheSound);
  225.  
  226.         theSnd := GetNamedResource('snd ', whichOne);
  227.  
  228.         if (theSnd^ = nil) then
  229.             Exit(DoTheSound);
  230.  
  231.         if (chanPtr <> nil) then
  232.             begin
  233.                 with aCommand do
  234.                     begin
  235.                         cmd := quietCmd;
  236.                         param1 := 0;
  237.                         param2 := 0;
  238.                     end;
  239.                 err := SndDoImmediate(chanPtr, aCommand);
  240.                 err := SndDisposeChannel(chanPtr, TRUE);
  241.                 chanPtr := nil;
  242.             end;
  243.  
  244.         err := SndNewChannel(chanPtr, 0, initMono + $0004, @ChanCallBack);
  245.         if (err = noErr) then
  246.             err := SndPlay(chanPtr, theSnd, TRUE);
  247.         with aCommand do
  248.             begin
  249.                 cmd := callBackCmd;
  250.                 param1 := 12345;
  251.                 param2 := GetA5;
  252.             end;
  253.         if (err = noErr) then
  254.             err := SndDoCommand(chanPtr, aCommand, FALSE);
  255.  
  256.         if (err = noErr) then
  257.             soundPriority := priority
  258.         else
  259.             soundPriority := noSound;
  260.     end;
  261.  
  262. {=================================}
  263.  
  264.     function DoRandom;
  265.         var
  266.             rawResult: LongInt;
  267.     begin
  268.         rawResult := Abs(Random);
  269.         DoRandom := (rawResult * range) div 32768
  270.     end;
  271.  
  272. {=================================}
  273.  
  274.     procedure ChangeRect;
  275.         var
  276.             hori, vert: Integer;
  277.     begin
  278.         with thePlayer do
  279.             begin
  280.                 hori := dest.left;
  281.                 vert := dest.top;
  282.                 if (mode < 6) then
  283.                     begin
  284.                         dest := playerRects[facing, mode];
  285.                         OffsetRect(dest, -dest.left, -dest.top);
  286.                     end
  287.                 else
  288.                     begin
  289.                         SetRect(dest, 0, 0, 45, 22);        {pile of bones rect}
  290.                         dest.top := dest.top + 17;            { h diff from skeleton to bone pile}
  291.                         dest.bottom := dest.bottom + 17;
  292.                     end;
  293.                 dest.left := dest.left + hori;
  294.                 dest.right := dest.right + hori;
  295.                 dest.top := dest.top + vert;
  296.                 dest.bottom := dest.bottom + vert;
  297.             end;
  298.     end;
  299.  
  300. {=================================}
  301.  
  302.     procedure DrawPlayer;
  303.         var
  304.             index, hori, vert: integer;
  305.             dummyLong: LongInt;
  306.             standInRect, standInRect2, tempRect: Rect;
  307.     begin
  308.         with thePlayer do
  309.             case mode of
  310.                 0..5: 
  311.                     begin
  312.                         UnionRect(oldRect, newRect, wholeRect);
  313.                         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, wholeRect, wholeRect, srcCopy, nil);
  314.                         CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, playerRects[facing, mode], playerRects[facing, mode], newRect);
  315.                         CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, wholeRect, wholeRect, srcCopy, playRgn);
  316.                         if (otherState) then        {brief flash as player dies and turns to a falling skeleton}
  317.                             begin
  318.                                 mode := 6;
  319.                                 CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, wholeRect, wholeRect, srcCopy, playRgn);
  320.                                 hori := newRect.left;
  321.                                 vert := newRect.top;
  322.                                 newRect := boneRects[0, 6];
  323.                                 OffsetRect(newRect, -newRect.left, -newRect.top);
  324.                                 tempRect := newRect;
  325.                                 OffsetRect(newRect, hori, vert);
  326.                                 dest := newRect;
  327.                                 if (dest.bottom < 200) then
  328.                                     OffsetRect(tempRect, 0, 200);
  329.                                 SetPort(GrafPtr(loadCPtr));
  330.                                 for index := 1 to 10 do
  331.                                     begin
  332.                                         EraseRect(tempRect);
  333.                                         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, newRect, tempRect, srcCopy, nil);
  334.                                         CopyMask(BitMapPtr(loadCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, tempRect, boneRects[facing, mode], newRect);
  335.                                         CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, newRect, newRect, srcCopy, playRgn);
  336.                                         Delay(1, dummyLong);
  337.                                         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, newRect, newRect, srcCopy, nil);
  338.                                         CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, boneRects[facing, mode], boneRects[facing, mode], newRect);
  339.                                         CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, newRect, newRect, srcCopy, playRgn);
  340.                                     end;
  341.                                 CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, newRect, newRect, srcCopy, playRgn);
  342.                             end;
  343.                     end;
  344.                 6:                     {falling skeleton}
  345.                     begin
  346.                         UnionRect(oldRect, newRect, wholeRect);
  347.                         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, wholeRect, wholeRect, srcCopy, nil);
  348.                         CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, boneRects[facing, mode], boneRects[facing, mode], newRect);
  349.                         CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, wholeRect, wholeRect, srcCopy, playRgn);
  350.                     end;
  351.                 7..100:         {sinking bones}
  352.                     begin
  353.                         UnionRect(oldRect, newRect, wholeRect);
  354.                         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, wholeRect, wholeRect, srcCopy, nil);
  355.                         standInRect := boneRects[facing, 7];
  356.                         standInRect2 := boneRects[facing, 7];
  357.                         vert := dest.bottom - dest.top;
  358.                         standInRect.bottom := standInRect.top + vert;
  359.                         standInRect2.bottom := standInRect2.top + vert;
  360.                         CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, standInRect, standInRect2, newRect);
  361.                         CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, wholeRect, wholeRect, srcCopy, playRgn);
  362.                     end;
  363.                 otherwise
  364.                     begin
  365.                     end;
  366.             end;
  367.     end;
  368.  
  369. {=================================}
  370.  
  371.     procedure DrawHand;
  372.     begin
  373.         with theHand do
  374.             begin
  375.                 UnionRect(oldDest, dest, wholeRect);
  376.                 CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, wholeRect, wholeRect, srcCopy, nil);
  377.                 CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, handRects[mode], handRects[mode], dest);
  378.                 CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, wholeRect, wholeRect, srcCopy, playRgn);
  379.             end;
  380.     end;
  381.  
  382. {=================================}
  383.  
  384.     procedure DrawBeasts;
  385.         var
  386.             index: Integer;
  387.             otherRect, otherMask, tempSrc, tempMask: Rect;
  388.     begin
  389.  
  390.         if (levelOn < 11) then    {swap flames on background}
  391.             begin
  392.                 CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, flameRect[0], flameRect[0], srcCopy, nil);
  393.                 CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(virginCPtr^.portPixMap^)^, flameRect[1], flameRect[0], srcCopy, nil);
  394.                 CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, BitMapPtr(virginCPtr^.portPixMap^)^, flameRect[0], flameRect[1], srcCopy, nil);
  395.             end;
  396.  
  397. {copy all neccesary background rects to the load map}
  398.         with theEye do
  399.             if (mode > 0) then
  400.                 begin
  401.                     UnionRect(oldDest, dest, wholeRect);
  402.                     CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, wholeRect, wholeRect, srcCopy, nil);
  403.                 end;
  404.  
  405.         for index := 1 to numberOfEnemies do
  406.             with theEnemies[index] do
  407.                 begin
  408.                     UnionRect(oldDest, dest, wholeRect);
  409.                     CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, wholeRect, wholeRect, srcCopy, nil);
  410.                     oldDest := dest;
  411.                 end;
  412.  
  413. {copy the beasts through their masks onto the load map}
  414.         for index := 1 to numberOfEnemies do
  415.             with theEnemies[index] do
  416.                 case mode of
  417.                     -1000..-1: 
  418.                         begin
  419.                             tempSrc := eggRects;
  420.                             tempMask := eggRects;
  421.                             tempSrc.bottom := tempSrc.top + (dest.bottom - dest.top);
  422.                             tempMask.bottom := tempMask.top + (dest.bottom - dest.top);
  423.                             CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, tempSrc, tempMask, dest);
  424.                         end;
  425.                     0..5: 
  426.                         CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, enemyRects[otherMode, mode, facing], enemyRects[otherMode, mode, facing], dest);
  427.                     6: 
  428.                         begin
  429.                             otherRect := enemyRects[otherMode, 1, facing];
  430.                             otherRect.bottom := otherRect.top + (dest.bottom - dest.top);
  431.                             otherMask := enemyRects[otherMode, 1, facing];
  432.                             otherMask.bottom := otherMask.top + (dest.bottom - dest.top);
  433.                             CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, otherRect, otherMask, dest);
  434.                         end;
  435.                     otherwise
  436.                         ;
  437.                 end;    {case}
  438.  
  439.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, flameRect[0], flameRect[0], srcCopy, nil);
  440.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, flameRect[1], flameRect[1], srcCopy, nil);
  441.         {copy the sum bitmaps to the screen}
  442.         for index := 1 to numberOfEnemies do
  443.             with theEnemies[index] do
  444.                 CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, wholeRect, wholeRect, srcCopy, playRgn);
  445.  
  446.         with theEye do
  447.             if (mode > 0) then
  448.                 begin
  449.                     CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, eyeRects[otherMode], eyeRects[otherMode], dest);
  450.                     CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, wholeRect, wholeRect, srcCopy, playRgn);
  451.                     oldDest := dest;
  452.                 end;
  453.     end;
  454.  
  455. {=================================}
  456.  
  457.     procedure RedoTheBackground;
  458.         var
  459.             tempRect, anotherRect: Rect;
  460.             thePict: PicHandle;
  461.     begin
  462.         SetPort(GrafPtr(virginCPtr));                        {Set the port to my window}
  463.         thePict := GetPicture(backPictID);            {Get Picture into memory}
  464.         if (thePict <> nil) then                                {Only use handle if it is valid}
  465.             begin
  466.                 ClipRect(wholeArea);                                {Clip picture to this rectangle}
  467.                 HLock(Handle(thePict));                            {Lock the handle before using it}
  468.                 DrawPicture(thePict, wholeArea);        {Draw this picture}
  469.                 HUnLock(Handle(thePict));                        {Unlock the picture again}
  470.                 ReleaseResource(Handle(thePict));
  471.             end;
  472.  
  473.         if (numberOfStones > 2) then
  474.             begin            {draw top floor end stones}
  475.                 tempRect := longStoneSrc;
  476.                 OffsetRect(tempRect, -tempRect.left, -tempRect.top);    {Get it in upper left}
  477.                 OffsetRect(tempRect, tombRects[3].left, tombRects[3].top);
  478.                 CopyBits(BitMapPtr(objectCPtr^.portPixMap^)^, BitMapPtr(virginCPtr^.portPixMap^)^, longStoneSrc, tempRect, srcCopy, nil);
  479.  
  480.                 tempRect := longStoneSrc;
  481.                 OffsetRect(tempRect, -tempRect.left, -tempRect.top);    {Get it in upper left}
  482.                 OffsetRect(tempRect, tombRects[4].left, tombRects[4].top);
  483.                 CopyBits(BitMapPtr(objectCPtr^.portPixMap^)^, BitMapPtr(virginCPtr^.portPixMap^)^, longStoneSrc, tempRect, srcCopy, nil);
  484.             end;
  485.  
  486.         if ((numberOfStones > 4) and (levelOn <> 3)) then
  487.             begin
  488.                 CopyBits(BitMapPtr(objectCPtr^.portPixMap^)^, BitMapPtr(virginCPtr^.portPixMap^)^, shortStoneSrc, tombRects[5], srcCopy, nil);
  489.             end;
  490.  
  491.         if (levelOn < 3) then
  492.             begin                            {put covers over acid pools}
  493.                 tempRect := longStoneSrc;
  494.                 OffsetRect(tempRect, -tempRect.left, -tempRect.top);    {Get it in upper left}
  495.                 OffsetRect(tempRect, tombRects[-5].left, tombRects[-5].top);
  496.                 CopyBits(BitMapPtr(objectCPtr^.portPixMap^)^, BitMapPtr(virginCPtr^.portPixMap^)^, longStoneSrc, tempRect, srcCopy, playRgn);
  497.  
  498.                 tempRect := longStoneSrc;
  499.                 OffsetRect(tempRect, -tempRect.left, -tempRect.top);    {Get it in upper left}
  500.                 OffsetRect(tempRect, tombRects[-4].left, tombRects[-4].top);
  501.                 CopyBits(BitMapPtr(objectCPtr^.portPixMap^)^, BitMapPtr(virginCPtr^.portPixMap^)^, longStoneSrc, tempRect, srcCopy, playRgn);
  502.             end;
  503.  
  504.         if (levelOn > 10) then
  505.             begin
  506.                 SetPort(GrafPtr(virginCPtr));
  507.                 FillRect(flameRect[0], black);
  508.                 FillRect(flameRect[1], black);
  509.             end;
  510.  
  511.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, wholeArea, wholeArea, srcCopy, nil);
  512.         ShowScore;
  513.         ShowMortals;
  514.         ShowLevel;
  515.     end;
  516.  
  517. {=================================}
  518.  
  519.     procedure ShowScore;
  520.         var
  521.             wasPort: GrafPtr;
  522.             tempStr: Str255;
  523.             tempRect: Rect;
  524.     begin
  525.         GetPort(wasPort);
  526.         SetPort(GrafPtr(mainWndo));
  527.         SetRect(tempRect, 268, 438, 364, 458);
  528.         TextFont(0);
  529.         TextSize(12);
  530.         NumToString(score, tempStr);
  531.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, tempRect, tempRect, srcCopy, nil);
  532.         RGBForeColor(rgbWhite);
  533.         PenMode(srcOr);
  534.         MoveTo(270, 456);
  535.         DrawString(tempStr);
  536.         RGBForeColor(rgbBlack);
  537.         SetPort(GrafPtr(wasPort));
  538.     end;
  539.  
  540. {=================================}
  541.  
  542.     procedure ShowMortals;
  543.         var
  544.             wasPort: GrafPtr;
  545.             tempStr: Str255;
  546.             tempRect: Rect;
  547.     begin
  548.         GetPort(wasPort);
  549.         SetPort(GrafPtr(mainWndo));
  550.         SetRect(tempRect, 218, 438, 266, 458);
  551.         TextFont(0);
  552.         TextSize(12);
  553.         NumToString(mortals, tempStr);
  554.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, tempRect, tempRect, srcCopy, nil);
  555.         RGBForeColor(rgbWhite);
  556.         PenMode(srcOr);
  557.         MoveTo(220, 456);
  558.         DrawString(tempStr);
  559.         RGBForeColor(rgbBlack);
  560.         SetPort(GrafPtr(wasPort));
  561.     end;
  562.  
  563. {=================================}
  564.  
  565.     procedure ShowLevel;
  566.         var
  567.             wasPort: GrafPtr;
  568.             tempStr: Str255;
  569.             tempRect: Rect;
  570.     begin
  571.         GetPort(wasPort);
  572.         SetPort(GrafPtr(mainWndo));
  573.         SetRect(tempRect, 378, 438, 426, 458);
  574.         TextFont(0);
  575.         TextSize(12);
  576.         NumToString(levelOn, tempStr);
  577.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, tempRect, tempRect, srcCopy, nil);
  578.         RGBForeColor(rgbWhite);
  579.         PenMode(srcOr);
  580.         MoveTo(380, 456);
  581.         DrawString(tempStr);
  582.         RGBForeColor(rgbBlack);
  583.         SetPort(GrafPtr(wasPort));
  584.     end;
  585.  
  586. {=================================}
  587.  
  588.     procedure CheckExtraMortal;
  589.     begin
  590.         if (score > nextMortal) then
  591.             begin
  592.                 DoTheSound('bonus.snd', highPriority);    {You got an extra player!}
  593.                 mortals := mortals + 1;
  594.                 ShowMortals;
  595.                 nextMortal := nextMortal + newMortalPts;
  596.             end;
  597.     end;
  598.  
  599. {=================================}
  600.  
  601.     procedure ReDrawHiScores;
  602.         var
  603.             index, heightIs: Integer;
  604.             dummyLong: LongInt;
  605.             tempRect: Rect;
  606.             dummyString: Str255;
  607.     begin
  608.         SetPort(GrafPtr(loadCPtr));
  609.         PenNormal;
  610.         SetRect(tempRect, 207, 168, 434, 388);
  611.         FillRect(tempRect, black);
  612.         TextFont(1);
  613.         TextSize(9);
  614.         for index := 1 to 10 do    {Now we're going to loop through all the scores    }
  615.             begin
  616.                 RGBForeColor(rgbYellow);
  617.                 MoveTo(tempRect.left + 20, index * 14 + tempRect.top + 50);
  618.                 DrawString(hiStrings[index]);                            {Draw the name of person}
  619.                 RGBForeColor(rgbRed);
  620.                 MoveTo(370, index * 14 + tempRect.top + 50);
  621.                 NumToString(hiScores[index], dummyString);
  622.                 DrawString(dummyString);                                    {And draw their score}
  623.             end;                                                                                {Copy screen to virgin for updates}
  624.         RGBForeColor(rgbBlack);
  625.         heightIs := tempRect.bottom - tempRect.top;
  626.         tempRect.top := tempRect.bottom;
  627.         for index := 1 to heightIs div 4 do
  628.             begin
  629.                 tempRect.top := tempRect.top - 4;
  630.                 CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, tempRect, tempRect, srcCopy, nil);
  631.             end;
  632.  
  633.         SetPort(GrafPtr(mainWndo));
  634.         TextFont(0);
  635.         TextSize(12);
  636.         PenMode(srcOr);
  637.         RGBForeColor(rgbLtBlue);
  638.         MoveTo(tempRect.left + 20, tempRect.top + 30);
  639.         DrawString('Glypha II 1.1 High Scores');
  640.         RGBForeColor(rgbBlack);
  641.  
  642.         CopyBits(mainWndo^.portBits, BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portRect, mainWndo^.portRect, srcCopy, nil);
  643.     end;
  644.  
  645. {=================================}
  646.  
  647.     procedure ReadInScores;
  648.         type
  649.             scoreHandle = ^scorePtr;
  650.             scorePtr = ^score;
  651.             score = record
  652.                     data: array[0..9] of LongInt;
  653.                 end;
  654.  
  655.             nameHandle = ^namePtr;
  656.             namePtr = ^name;
  657.             name = record
  658.                     data: array[0..9, 0..14] of Char;
  659.                 end;
  660.  
  661.             prefHandle = ^prefPtr;
  662.             prefPtr = ^pref;
  663.             pref = record
  664.                     data: array[0..31] of Char;
  665.                 end;
  666.  
  667.         var
  668.             index, index2, tempVolume: Integer;
  669.             dummyStr: Str255;
  670.             theScores: scoreHandle;
  671.             theNames: nameHandle;
  672.             thePrefs: prefHandle;
  673.  
  674.     begin
  675.         theScores := scoreHandle(NewHandle(SIZEOF(score)));
  676.         if (theScores = nil) then
  677.             begin
  678.                 GenericAlert(4);
  679.                 ExitToShell;
  680.             end;
  681.         MoveHHi(Handle(theScores));
  682.         HLock(Handle(theScores));
  683.         Handle(theScores) := GetResource('scrs', 128);
  684.         for index := 0 to 9 do
  685.             hiScores[index + 1] := theScores^^.data[index];
  686.         HUnlock(Handle(theScores));
  687.         ReleaseResource(Handle(theScores));
  688.         DisposHandle(Handle(theScores));
  689.  
  690.         theNames := nameHandle(NewHandle(SIZEOF(name)));
  691.         if (theNames = nil) then
  692.             begin
  693.                 GenericAlert(4);
  694.                 ExitToShell;
  695.             end;
  696.         MoveHHi(Handle(theNames));
  697.         HLock(Handle(theNames));
  698.         Handle(theNames) := GetResource('name', 128);
  699.         for index := 0 to 9 do
  700.             begin
  701.                 dummyStr := '';
  702.                 for index2 := 0 to 14 do
  703.                     dummyStr := CONCAT(dummyStr, theNames^^.data[index, index2]);
  704.                 hiStrings[index + 1] := dummyStr;
  705.             end;
  706.         HUnlock(Handle(theNames));
  707.         ReleaseResource(Handle(theNames));
  708.         DisposHandle(Handle(theNames));
  709.  
  710.         thePrefs := prefHandle(NewHandle(SIZEOF(pref)));
  711.         if (thePrefs = nil) then
  712.             begin
  713.                 GenericAlert(4);
  714.                 ExitToShell;
  715.             end;
  716.         MoveHHi(Handle(thePrefs));
  717.         HLock(Handle(thePrefs));
  718.         Handle(thePrefs) := GetResource('pref', 128);
  719.  
  720.         if (thePrefs^^.data[0] = 'M') then
  721.             keyboardControl := FALSE
  722.         else
  723.             keyboardControl := TRUE;
  724.         if (thePrefs^^.data[1] = 'S') then
  725.             soundOn := TRUE
  726.         else
  727.             soundOn := FALSE;
  728.         if (inhibitSound) then
  729.             soundOn := FALSE;
  730.         GetSoundVol(tempVolume);
  731.         if (tempVolume = 0) then
  732.             soundOn := FALSE;
  733.  
  734.         case thePrefs^^.data[2] of
  735.             'S': 
  736.                 gameSpeed := slow;
  737.             'F': 
  738.                 gameSpeed := fast;
  739.             otherwise
  740.                 gameSpeed := fast;
  741.         end;
  742.  
  743.         nameUsing := '';
  744.         for index := 1 to 15 do
  745.             nameUsing := CONCAT(nameUsing, thePrefs^^.data[index + 16]);
  746.  
  747.         HUnlock(Handle(thePrefs));
  748.         ReleaseResource(Handle(thePrefs));
  749.         DisposHandle(Handle(thePrefs));
  750.  
  751.         scoresChanged := FALSE;
  752.     end;
  753.  
  754. {=================================}
  755.  
  756.     procedure WriteOutScores;
  757.         type
  758.             scoreHandle = ^scorePtr;
  759.             scorePtr = ^score;
  760.             score = record
  761.                     data: array[0..9] of LongInt;
  762.                 end;
  763.  
  764.             nameHandle = ^namePtr;
  765.             namePtr = ^name;
  766.             name = record
  767.                     data: array[0..9, 0..14] of Char;
  768.                 end;
  769.  
  770.             prefHandle = ^prefPtr;
  771.             prefPtr = ^pref;
  772.             pref = record
  773.                     data: array[0..31] of Char;
  774.                 end;
  775.  
  776.         var
  777.             index, index2: Integer;
  778.             dummyStr: Str255;
  779.             theScores: scoreHandle;
  780.             theNames: nameHandle;
  781.             thePrefs: prefHandle;
  782.  
  783.     begin
  784.         thePrefs := prefHandle(NewHandle(SIZEOF(pref)));
  785.         if (thePrefs = nil) then
  786.             begin
  787.                 GenericAlert(4);
  788.                 ExitToShell;
  789.             end;
  790.         HLock(Handle(thePrefs));
  791.         Handle(thePrefs) := GetResource('pref', 128);
  792.         if (keyboardControl) then
  793.             thePrefs^^.data[0] := 'K'
  794.         else
  795.             thePrefs^^.data[0] := 'M';
  796.         if (soundOn) then
  797.             thePrefs^^.data[1] := 'S'
  798.         else
  799.             thePrefs^^.data[1] := 'N';
  800.  
  801.         if (gameSpeed = slow) then
  802.             thePrefs^^.data[2] := 'S'
  803.         else
  804.             thePrefs^^.data[2] := 'F';
  805.  
  806.         for index := 1 to 15 do
  807.             thePrefs^^.data[index + 16] := COPY(nameUsing, index, 1);
  808.         ChangedResource(Handle(thePrefs));
  809.         WriteResource(Handle(thePrefs));
  810.         HUnlock(Handle(thePrefs));
  811.         ReleaseResource(Handle(thePrefs));
  812.         DisposHandle(Handle(thePrefs));
  813.  
  814.         if (scoresChanged) then
  815.             begin
  816.                 theScores := scoreHandle(NewHandle(SIZEOF(score)));
  817.                 if (theScores = nil) then
  818.                     begin
  819.                         GenericAlert(4);
  820.                         ExitToShell;
  821.                     end;
  822.                 MoveHHi(Handle(theScores));
  823.                 HLock(Handle(theScores));
  824.                 Handle(theScores) := GetResource('scrs', 128);
  825.                 for index := 0 to 9 do
  826.                     theScores^^.data[index] := hiScores[index + 1];
  827.                 ChangedResource(Handle(theScores));
  828.                 WriteResource(Handle(theScores));
  829.                 HUnlock(Handle(theScores));
  830.                 ReleaseResource(Handle(theScores));
  831.                 DisposHandle(Handle(theScores));
  832.  
  833.                 theNames := nameHandle(NewHandle(SIZEOF(name)));
  834.                 if (theNames = nil) then
  835.                     begin
  836.                         GenericAlert(4);
  837.                         ExitToShell;
  838.                     end;
  839.                 HLock(Handle(theNames));
  840.                 Handle(theNames) := GetResource('name', 128);
  841.                 for index := 0 to 9 do
  842.                     for index2 := 0 to 14 do
  843.                         theNames^^.data[index, index2] := COPY(hiStrings[index + 1], index2 + 1, 1);
  844.                 ChangedResource(Handle(theNames));
  845.                 WriteResource(Handle(theNames));
  846.                 HUnlock(Handle(theNames));
  847.                 ReleaseResource(Handle(theNames));
  848.                 DisposHandle(Handle(theNames));
  849.             end;
  850.     end;
  851.  
  852. {=================================}
  853.  
  854.     procedure FinalScore;
  855.         var
  856.             index, ranking: Integer;
  857.     begin
  858.         FlushEvents(everyEvent, 0);                                    {Clear all the keystrokes    }
  859.         if (score > hiScores[10]) and (mortalsStart = defaultNum) then        {Is it a high score?            }
  860.             begin
  861.                 scoresChanged := TRUE;                        {Mark scores as changed            }
  862.                 DoTheSound('bonus.snd', highPriority);        {Play the bonus sound.            }
  863.                 ranking := 10;                                        {And sort through the high    }
  864.                 for index := 9 downto 1 do                {scores to find the players    }
  865.                     begin                                                        {ranking.                                        }
  866.                         if (score > hiScores[index]) then
  867.                             ranking := index;
  868.                     end;
  869.                 for index := 10 downto ranking + 1 do
  870.                     begin
  871.                         hiScores[index] := hiScores[index - 1];        {Move everyone's score}
  872.                         hiStrings[index] := hiStrings[index - 1];    {down the list.                }
  873.                     end;
  874.                 hiScores[ranking] := score;
  875.                 SetPort(GrafPtr(mainWndo));
  876.                 WhosHiScore(nameUsing);
  877.                 hiStrings[ranking] := nameUsing;
  878.             end;
  879.     end;
  880.  
  881. {=================================}
  882.  
  883.     procedure DoHelpScreen;
  884.         const
  885.             helpLeft = 208;
  886.             helpTop = 170;
  887.         var
  888.             index: Integer;
  889.             srcRect, dropRect: Rect;
  890.             thePict: PicHandle;
  891.     begin
  892.         SetPort(GrafPtr(loadCPtr));
  893.         thePict := GetPicture(helpPictID);
  894.         SetRect(dropRect, 0, 0, 452, 440);
  895.         if (thePict <> nil) then
  896.             begin
  897.                 HLock(Handle(thePict));
  898.                 DrawPicture(thePict, dropRect);
  899.                 HUnLock(Handle(thePict));
  900.                 ReleaseResource(Handle(thePict));
  901.             end
  902.         else
  903.             Exit(DoHelpScreen);
  904.  
  905.         SetRect(dropRect, 0 + helpLeft, helpTop + 220, 226 + helpLeft, helpTop + 220);
  906.         SetRect(srcRect, 0, 0, 226, 0);
  907.         for index := 1 to 110 do
  908.             begin
  909.                 dropRect.top := dropRect.top - 2;
  910.                 srcRect.bottom := srcRect.bottom + 2;
  911.                 CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, srcRect, dropRect, srcCopy, nil);
  912.             end;
  913.         repeat
  914.         until not Button;
  915.         repeat
  916.         until Button;
  917.  
  918.         SetRect(dropRect, 0 + helpLeft, helpTop + 220, 226 + helpLeft, helpTop + 220);
  919.         SetRect(srcRect, 226, 0, 452, 0);
  920.         for index := 1 to 110 do
  921.             begin
  922.                 dropRect.top := dropRect.top - 2;
  923.                 srcRect.bottom := srcRect.bottom + 2;
  924.                 CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, srcRect, dropRect, srcCopy, nil);
  925.             end;
  926.         repeat
  927.         until not Button;
  928.         repeat
  929.         until Button;
  930.  
  931.         SetRect(dropRect, 0 + helpLeft, helpTop + 220, 226 + helpLeft, helpTop + 220);
  932.         SetRect(srcRect, 226, 220, 452, 220);
  933.         for index := 1 to 110 do
  934.             begin
  935.                 dropRect.top := dropRect.top - 2;
  936.                 srcRect.bottom := srcRect.bottom + 2;
  937.                 CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, srcRect, dropRect, srcCopy, nil);
  938.             end;
  939.         repeat
  940.         until not Button;
  941.         repeat
  942.         until Button;
  943.  
  944.         SetRect(dropRect, 0 + helpLeft, helpTop + 220, 226 + helpLeft, helpTop + 220);
  945.         SetRect(srcRect, 0, 220, 226, 220);
  946.         for index := 1 to 110 do
  947.             begin
  948.                 dropRect.top := dropRect.top - 2;
  949.                 srcRect.bottom := srcRect.bottom + 2;
  950.                 CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, srcRect, dropRect, srcCopy, nil);
  951.             end;
  952.         repeat
  953.         until not Button;
  954.         repeat
  955.         until Button;
  956.  
  957.         FlushEvents(everyEvent, 0);
  958.         RedrawHiScores;
  959.     end;
  960.  
  961. {=================================}
  962.  
  963.     procedure FlushTheScores;
  964.         var
  965.             index: Integer;
  966.     begin
  967.         for index := 1 to 10 do
  968.             begin
  969.                 hiScores[index] := 0;
  970.                 hiStrings[index] := 'Play Me .......';
  971.             end;
  972.         scoresChanged := TRUE;
  973.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, wholeArea, wholeArea, srcCopy, nil);
  974.         RedrawHiScores;
  975.     end;
  976.  
  977. {=================================}
  978.  
  979. end.